﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.IdentityModel.Tokens;
using SmartSiteManagementSystem.IServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

using Microsoft.AspNetCore.Authorization;
using System.IdentityModel.Tokens.Jwt;
using SmartSiteManagementSystem.Services.Jwt;
using System.Collections;
using SmartSiteManagementSystem.Models.User;
using SmartSiteManagementSystem.Models.DTO;
using SmartSiteManagementSystem.Models.Enums;
using SmartSiteManagementSystem.Utils;
using SmartSiteManagementSystem.AppApi.RequestBodyInputParamDto;
using SmartSiteManagementSystem.AppApi.Common;
using SmartSiteManagementSystem.AppApi.ResponseBodyOutputParamDto;

using SmartSiteManagementSystem.Models.ProjectManage;
using Microsoft.Extensions.Logging;

namespace SmartSiteManagementSystem.AppApi.Controllers
{
    /// <summary>
    /// 
    /// </summary>
    [Route("api/[controller]")]
    [AllowAnonymous]
    [ApiController]
    public class UserController : ApiBaseController
    {
        private readonly IUserService _userService;
        private readonly IHttpContextAccessor _httpContext;
        private readonly IJWTService _iJWTService;
        private readonly IProjectManageService _projectManageService;
        private readonly ILogger<UserController> _logger;
        /// <summary>
        /// 
        /// </summary>
        public UserController(IUserService userService, IProjectManageService projectManageService, IHttpContextAccessor httpContext, IJWTService iJWTService,
           ILogger<UserController> logger)
        {
            _userService = userService;
            _projectManageService = projectManageService;
            _httpContext = httpContext;
            _iJWTService = iJWTService;
            _logger = logger;
        }

        /// <summary>
        /// 登录接口API
        /// </summary>
        /// <param name="userLoginRequestBodyParamDto">请求内容 {"loginName":"xxx","loginPwd":"sssss"}</param>
        /// <returns></returns>
       
        [HttpPost("Login")]
        public IActionResult Login([FromBody] UserLoginRequestBodyParamDto userLoginRequestBodyParamDto)
        {
            SSMSApiResult<Hashtable> reslut = new SSMSApiResult<Hashtable>();
            reslut.Code = StateCodeEnum.Fail;
            reslut.Data = new Hashtable();
            reslut.Msg = "操作失败";
            ApiRequestCustomHeadInfo apiRequestCustomHeadInfo = RequestHeadHelper.GetApiRequestCustomHeadInfo(_httpContext.HttpContext);
            try
            {
                if (string.IsNullOrEmpty(userLoginRequestBodyParamDto.LoginName) || string.IsNullOrEmpty(userLoginRequestBodyParamDto.LoginPwd))
                {
                    #region 提交数据为空
                    reslut.Code = StateCodeEnum.LackSubmitParam;
                    reslut.Msg = "登录名和密码不能为空";
                    #endregion
                }
                else
                {
                    #region 主要业务

                     UserInfo userInfo =  _userService.GetUserInfoByLogin(userLoginRequestBodyParamDto.LoginName);
                    if (userInfo != null)
                    {

                        #region 用户存在
                        string encryptLoginPwd = EncryptionUtils.GetUserLoginPwd_SHA1(userLoginRequestBodyParamDto.LoginName, userLoginRequestBodyParamDto.LoginPwd);
                        if(encryptLoginPwd== userInfo.LogonPwd)
                        {
                            string token = _iJWTService.GetToken(userInfo.LogonName);
                            Hashtable param = new Hashtable();
                            #region 密码正确
                            reslut.Code = StateCodeEnum.Ok;
                            reslut.Msg = "登录成功!";
                            param.Add("asessToken", token);
                            param.Add("userId", userInfo.UserId);
                            param.Add("auth", EncryptionUtils.GetUserLoginAuth_SHA1(userInfo.LogonName, userInfo.LogonPwd));
                            reslut.Data = param;
                            #region 更新用户登录信息
                            userInfo.LoginCount = userInfo.LoginCount + 1;
                            userInfo.LastestLogonTime = DateTime.Now;
                            userInfo.LastestLogonIp = IPUtils.GetIPRealAddress(HttpContext);
                            _userService.UpdateUserInfo(userInfo);
                            #endregion
                            #endregion
                        }
                        else
                        {
                            #region 密码不正确
                            reslut.Code = StateCodeEnum.Fail;
                            reslut.Msg = "密码不正确!";
                            #endregion

                        }
                        #endregion
                    }
                    else
                    {
                        #region 用户不存在
                        reslut.Code = StateCodeEnum.Fail;
                        reslut.Msg = "账号不存在";
                        #endregion
                    }
                    
                    #endregion
                }
            }
            catch(Exception e)
            {
                reslut.Code = StateCodeEnum.InternalServerError;
                reslut.Msg = "服务器错误";

            }
            return Ok(reslut);
        }



        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="userIdTokenRequestBodyParamDto"></param>
        /// <returns></returns>
        //[Authorize]
        [HttpPost, Route("GetUserInfo")]
        public IActionResult GetUserInfo([FromBody] UserIdTokenRequestBodyParamDto userIdTokenRequestBodyParamDto)
        {
            SSMSApiResult<Hashtable> reslut = new SSMSApiResult<Hashtable>();
            reslut.Code = StateCodeEnum.Fail;
            reslut.Data = new Hashtable();
            reslut.Msg = "操作失败";
            ApiRequestCustomHeadInfo apiRequestCustomHeadInfo = RequestHeadHelper.GetApiRequestCustomHeadInfo(_httpContext.HttpContext);
            try
            {
                if (string.IsNullOrEmpty(userIdTokenRequestBodyParamDto.Auth) || userIdTokenRequestBodyParamDto.UserId==0)
                {
                    #region 提交数据为空
                    reslut.Code = StateCodeEnum.LackSubmitParam;
                    reslut.Msg = "提交参数不能为空";
                    #endregion
                }
                else
                {
                    #region 主要业务

                    UserInfo userInfo = _userService.GetUserInfoById(userIdTokenRequestBodyParamDto.UserId);

                    if (userInfo != null)
                    {

                        #region 用户存在
                        string encryptAuth = EncryptionUtils.GetUserLoginAuth_SHA1(userInfo.LogonName, userInfo.LogonPwd);
                        if (encryptAuth == userIdTokenRequestBodyParamDto.Auth)
                        {
                            GetUserInfoResponseBodyParamDto getUserInfoResponseBodyParamDto = new GetUserInfoResponseBodyParamDto{
                                 LogonName=userInfo.LogonName,
                                 LastestLogonTime=userInfo.LastestLogonTime,
                                 UserId=userInfo.UserId,
                                 Email=userInfo.Email,
                                 HeadPic=userInfo.HeadPic,
                                 Mobile=userInfo.Mobile,
                                 Sex=userInfo.Sex,
                                 PositionType=userInfo.PositionType,
                                 RegTypeName=userInfo.PositionTypeName,
                                 ShowName=userInfo.ShowName
                            };
                            Hashtable useinfoHashtable = new Hashtable();
                            useinfoHashtable.Add("userInfo", getUserInfoResponseBodyParamDto);
                            #region 密码正确
                            reslut.Code = StateCodeEnum.Ok;
                            reslut.Msg = "操作成功!";
                            reslut.Data = useinfoHashtable;
                            #endregion
                        }
                        else
                        {
                            #region 密码不正确
                            reslut.Code = StateCodeEnum.Fail;
                            reslut.Msg = "密码不正确!";
                            #endregion

                        }
                        #endregion
                    }
                    else
                    {
                        #region 用户不存在
                        reslut.Code = StateCodeEnum.Fail;
                        reslut.Msg = "账号不存在";
                        #endregion
                    }

                    #endregion
                }
            }
            catch (Exception e)
            {
                reslut.Code = StateCodeEnum.InternalServerError;
                reslut.Msg = "服务器错误";

            }
            return Ok(reslut);
        }



        /// <summary>
        /// 用户修改密码
        /// </summary>
        /// <param name="userModifyPasswordRequestBodyParamDto"></param>
        /// <returns></returns>
        //[Authorize]
        [HttpPost, Route("UserModifyPassword")]
        public IActionResult UserModifyPassword([FromBody] UserModifyPasswordRequestBodyParamDto userModifyPasswordRequestBodyParamDto)
        {
            SSMSApiResult<Hashtable> reslut = new SSMSApiResult<Hashtable>();
            reslut.Code = StateCodeEnum.Fail;
            reslut.Data = new Hashtable();
            reslut.Msg = "操作失败";
            ApiRequestCustomHeadInfo apiRequestCustomHeadInfo = RequestHeadHelper.GetApiRequestCustomHeadInfo(_httpContext.HttpContext);
            try
            {
                if (string.IsNullOrEmpty(userModifyPasswordRequestBodyParamDto.Auth) || userModifyPasswordRequestBodyParamDto.UserId == 0||string.IsNullOrEmpty(userModifyPasswordRequestBodyParamDto.NewPassword))
                {
                    #region 提交数据为空
                    reslut.Code = StateCodeEnum.LackSubmitParam;
                    reslut.Msg = "提交参数不能为空";
                    #endregion
                }
                else
                {
                    #region 主要业务

                    UserInfo userInfo = _userService.GetUserInfoById(userModifyPasswordRequestBodyParamDto.UserId);

                    if (userInfo != null)
                    {

                        #region 用户存在
                        string encryptAuth = EncryptionUtils.GetUserLoginAuth_SHA1(userInfo.LogonName, userInfo.LogonPwd);
                        if (encryptAuth == userModifyPasswordRequestBodyParamDto.Auth)
                        {
                            #region 密码正确

                            userInfo.LogonPwd = EncryptionUtils.GetUserLoginPwd_SHA1(userInfo.LogonName, userModifyPasswordRequestBodyParamDto.NewPassword);
                            if(_userService.UpdateUserInfo(userInfo))
                            {
                                Hashtable useinfoHashtable = new Hashtable();
                                useinfoHashtable.Add("userId", userInfo.UserId);
                                useinfoHashtable.Add("auth", EncryptionUtils.GetUserLoginAuth_SHA1(userInfo.LogonName, userInfo.LogonPwd));
                                reslut.Code = StateCodeEnum.Ok;
                                reslut.Msg = "操作成功!";
                                reslut.Data = useinfoHashtable;
                            }
                            else
                            {
                                reslut.Code = StateCodeEnum.Fail;
                                reslut.Msg = "操作失败!";
                                reslut.Data = new Hashtable();
                            }
                            #endregion
                        }
                        else
                        {
                            #region 密码不正确
                            reslut.Code = StateCodeEnum.Fail;
                            reslut.Msg = "密码不正确!";
                            #endregion

                        }
                        #endregion
                    }
                    else
                    {
                        #region 用户不存在
                        reslut.Code = StateCodeEnum.Fail;
                        reslut.Msg = "账号不存在";
                        #endregion
                    }

                    #endregion
                }
            }
            catch (Exception e)
            {
                reslut.Code = StateCodeEnum.InternalServerError;
                reslut.Msg = "服务器错误";

            }
            return Ok(reslut);
        }


        /// <summary>
        /// 获取用户日计划 
        /// </summary>
        /// <param name="userIdTokenRequestWithPagerBodyParamDto"></param>
        /// <returns></returns>
        //[Authorize]
        [HttpPost, Route("GetUserDayProject")]
        public IActionResult GetUserDayProject([FromBody] UserIdTokenRequestWithPagerBodyParamDto userIdTokenRequestWithPagerBodyParamDto)
        {
            SSMSApiResult<Hashtable> reslut = new SSMSApiResult<Hashtable>();
            reslut.Code = StateCodeEnum.Fail;
            reslut.Data = new Hashtable();
            reslut.Msg = "操作失败";
            ApiRequestCustomHeadInfo apiRequestCustomHeadInfo = RequestHeadHelper.GetApiRequestCustomHeadInfo(_httpContext.HttpContext);
            try
            {
                if (string.IsNullOrEmpty(userIdTokenRequestWithPagerBodyParamDto.Auth) || userIdTokenRequestWithPagerBodyParamDto.UserId == 0 || userIdTokenRequestWithPagerBodyParamDto.Rows==0)
                {
                    #region 提交数据为空
                    reslut.Code = StateCodeEnum.LackSubmitParam;
                    reslut.Msg = "提交参数不能为空";
                    #endregion
                }
                else
                {
                    #region 主要业务

                    UserInfo userInfo = _userService.GetUserInfoById(userIdTokenRequestWithPagerBodyParamDto.UserId);

                    if (userInfo != null)
                    {


                        #region 用户存在
                        string encryptAuth = EncryptionUtils.GetUserLoginAuth_SHA1(userInfo.LogonName, userInfo.LogonPwd);
                        if (encryptAuth == userIdTokenRequestWithPagerBodyParamDto.Auth)
                        {
                            #region 密码正确 业务主体

                            Hashtable param = new Hashtable();
                            param.Add("user_id", userIdTokenRequestWithPagerBodyParamDto.UserId);
                            if(userIdTokenRequestWithPagerBodyParamDto.SelectStatus==1)
                            {
                                param.Add("status_type", 10);
                            }
                            else if(userIdTokenRequestWithPagerBodyParamDto.SelectStatus ==2)
                            {
                                param.Add("status_type", 15);
                            }
                            param.Add("is_delete", 0);//正常 0 false
                            int count = _projectManageService.GetDayProjectInfoListCount(param);
                            IList<DayProjectInfo> dayProjectInfolist = _projectManageService.GetDayProjectInfoList(param, "", userIdTokenRequestWithPagerBodyParamDto.First, userIdTokenRequestWithPagerBodyParamDto.Rows);
                            Hashtable dayProjectTypeParam = new Hashtable();
                            dayProjectTypeParam.Add("is_delete", 0);
                            IList<DayProjectTypeInfo> dayProjectTypeInfolist = _projectManageService.GetDayProjectTypeInfoList(dayProjectTypeParam, "",0, 1000);

                            IList<UserDayProjectResponseBodyParamDto> responseList = new List<UserDayProjectResponseBodyParamDto>();
                            foreach(DayProjectInfo item in dayProjectInfolist)
                            {
                                string dayProjectTypeStr = GetDayProjectTypeStr(dayProjectTypeInfolist, item.DayProjectType);
                                ProjectInfo projectInfo = _projectManageService.GetProjectInfoById(item.DayProjectId);
                                string projectName = "";
                                if(projectInfo!=null)
                                {
                                    projectName = projectInfo.ProjectName;
                                }
                                string statusTypeStr = GetStatusTypeStr(item.StatusType);
                                UserDayProjectResponseBodyParamDto userDayProjectResponseBodyParamDto = new UserDayProjectResponseBodyParamDto
                                {
                                    DayProjectId = item.DayProjectId,
                                    DayProjectName = item.DayProjectName,
                                    ProjectId = item.ProjectId,
                                    DayProjectType = item.DayProjectType,
                                    DayProjectTypeStr = dayProjectTypeStr,
                                    ProjectName = projectName,
                                    StartTime = item.StartTime,
                                    EndTime = item.EndTime,
                                    StartTimeStr = item.StartTime.ToString("yyyy-MM-dd HH:mm:ss"),
                                    EndTimeStr = item.EndTime.ToString("yyyy-MM-dd HH:mm:ss"),
                                    StatusType = item.StatusType,
                                    StatusTypeStr = statusTypeStr,
                                    IssueTime = item.IssueTime,
                                    IssueTimeStr= item.IssueTime.ToString("yyyy-MM-dd HH:mm:ss")
                                };
                                responseList.Add(userDayProjectResponseBodyParamDto);
                            }
  
                            Hashtable useinfoHashtable = new Hashtable();
                            useinfoHashtable.Add("userDayProjectCount", count);
                            useinfoHashtable.Add("userDayProjectList", responseList);
                            
                            reslut.Code = StateCodeEnum.Ok;
                            reslut.Msg = "操作成功!";
                            reslut.Data = useinfoHashtable;
                            #endregion
                        }
                        else
                        {
                            #region 密码不正确
                            reslut.Code = StateCodeEnum.Fail;
                            reslut.Msg = "密码不正确!";
                            #endregion

                        }
                        #endregion
                    }
                    else
                    {
                        #region 用户不存在
                        reslut.Code = StateCodeEnum.Fail;
                        reslut.Msg = "账号不存在";
                        #endregion
                    }

                    #endregion
                }
            }
            catch (Exception e)
            {
                reslut.Code = StateCodeEnum.InternalServerError;
                _logger.LogError("userdayproject服务器错误" + e.Message.ToString());
                reslut.Msg = "服务器错误";

            }
            return Ok(reslut);
        }



        /// <summary>
        /// 获取用户日计划详细 
        /// </summary>
        /// <param name="dayProjectDetailRequestrBodyParamDto"></param>
        /// <returns></returns>
       // [Authorize]
        [HttpPost, Route("GetUserDayProjectDetail")]
        public IActionResult GetUserDayProjectDetail([FromBody] DayProjectDetailRequestBodyParamDto dayProjectDetailRequestrBodyParamDto)
        {
            SSMSApiResult<Hashtable> reslut = new SSMSApiResult<Hashtable>();
            reslut.Code = StateCodeEnum.Fail;
            reslut.Data = new Hashtable();
            reslut.Msg = "操作失败";
            ApiRequestCustomHeadInfo apiRequestCustomHeadInfo = RequestHeadHelper.GetApiRequestCustomHeadInfo(_httpContext.HttpContext);
            try
            {
                if (string.IsNullOrEmpty(dayProjectDetailRequestrBodyParamDto.Auth) || dayProjectDetailRequestrBodyParamDto.UserId == 0 || dayProjectDetailRequestrBodyParamDto.DayProjectId == 0)
                {
                    #region 提交数据为空
                    reslut.Code = StateCodeEnum.LackSubmitParam;
                    reslut.Msg = "提交参数不能为空";
                    #endregion
                }
                else
                {
                    #region 主要业务

                    UserInfo userInfo = _userService.GetUserInfoById(dayProjectDetailRequestrBodyParamDto.UserId);

                    if (userInfo != null)
                    {


                        #region 用户存在
                        string encryptAuth = EncryptionUtils.GetUserLoginAuth_SHA1(userInfo.LogonName, userInfo.LogonPwd);
                        if (encryptAuth == dayProjectDetailRequestrBodyParamDto.Auth)
                        {
                            #region 密码正确 业务主体

                            UserDayProjectResponseBodyParamDto userDayProjectResponseBodyParamDto = new UserDayProjectResponseBodyParamDto();

                            DayProjectInfo dayProjectInfo = _projectManageService.GetDayProjectInfoById(dayProjectDetailRequestrBodyParamDto.DayProjectId);
                            if (dayProjectInfo != null)
                            {
                                string dayProjectTypeStr = "";
                                DayProjectTypeInfo dayProjectTypeInfo = _projectManageService.GetDayProjectTypeInfoById(dayProjectInfo.DayProjectType);
                                if(dayProjectTypeInfo!=null)
                                {
                                    dayProjectTypeStr = dayProjectTypeInfo.DayProjectTypeName;
                                }

                                ProjectInfo projectInfo = _projectManageService.GetProjectInfoById(dayProjectInfo.DayProjectId);
                                string projectName = "";
                                if (projectInfo != null)
                                {
                                    projectName = projectInfo.ProjectName;
                                }
                                string statusTypeStr = GetStatusTypeStr(dayProjectInfo.StatusType);
                                userDayProjectResponseBodyParamDto.DayProjectId = dayProjectInfo.DayProjectId;
                                userDayProjectResponseBodyParamDto.DayProjectName = dayProjectInfo.DayProjectName;
                                userDayProjectResponseBodyParamDto.ProjectId = dayProjectInfo.ProjectId;
                                userDayProjectResponseBodyParamDto.DayProjectType = dayProjectInfo.DayProjectType;
                                userDayProjectResponseBodyParamDto.DayProjectTypeStr = dayProjectTypeStr;
                                userDayProjectResponseBodyParamDto.ProjectName = projectName;
                                userDayProjectResponseBodyParamDto.StartTime = dayProjectInfo.StartTime;
                                userDayProjectResponseBodyParamDto.EndTime = dayProjectInfo.EndTime;
                                userDayProjectResponseBodyParamDto.StartTimeStr = dayProjectInfo.StartTime.ToString("yyyy-MM-dd HH:mm:ss");
                                userDayProjectResponseBodyParamDto.EndTimeStr = dayProjectInfo.EndTime.ToString("yyyy-MM-dd HH:mm:ss");
                                userDayProjectResponseBodyParamDto.StatusType = dayProjectInfo.StatusType;
                                userDayProjectResponseBodyParamDto.StatusTypeStr = statusTypeStr;
                                userDayProjectResponseBodyParamDto.IssueTime = dayProjectInfo.IssueTime;
                                userDayProjectResponseBodyParamDto.IssueTimeStr = dayProjectInfo.IssueTime.ToString("yyyy-MM-dd HH:mm:ss");
                         
                              
                            }
                            Hashtable userDayProjectInfoHashtable = new Hashtable();
                            userDayProjectInfoHashtable.Add("userDayProject", userDayProjectResponseBodyParamDto);

                            reslut.Code = StateCodeEnum.Ok;
                            reslut.Msg = "操作成功!";
                            reslut.Data = userDayProjectInfoHashtable;
                            #endregion
                        }
                        else
                        {
                            #region 密码不正确
                            reslut.Code = StateCodeEnum.Fail;
                            reslut.Msg = "密码不正确!";
                            #endregion

                        }
                        #endregion
                    }
                    else
                    {
                        #region 用户不存在
                        reslut.Code = StateCodeEnum.Fail;
                        reslut.Msg = "账号不存在";
                        #endregion
                    }

                    #endregion
                }
            }
            catch (Exception e)
            {
                reslut.Code = StateCodeEnum.InternalServerError;
                _logger.LogError("userdayprojectdetail服务器错误" + e.Message.ToString());
                reslut.Msg = "服务器错误";

            }
            return Ok(reslut);
        }



        /// <summary>
        /// 完成任务
        /// </summary>
        /// <param name="dayProjectDetailRequestrBodyParamDto"></param>
        /// <returns></returns>
        //[Authorize]
        [HttpPost, Route("DoDayProjectComplete")]
        public IActionResult DoDayProjectComplete([FromBody] DayProjectDetailRequestBodyParamDto dayProjectDetailRequestrBodyParamDto)
        {
            SSMSApiResult<Hashtable> reslut = new SSMSApiResult<Hashtable>();
            reslut.Code = StateCodeEnum.Fail;
            reslut.Data = new Hashtable();
            reslut.Msg = "操作失败";
            ApiRequestCustomHeadInfo apiRequestCustomHeadInfo = RequestHeadHelper.GetApiRequestCustomHeadInfo(_httpContext.HttpContext);
            try
            {
                if (string.IsNullOrEmpty(dayProjectDetailRequestrBodyParamDto.Auth) || dayProjectDetailRequestrBodyParamDto.UserId == 0 || dayProjectDetailRequestrBodyParamDto.DayProjectId == 0)
                {
                    #region 提交数据为空
                    reslut.Code = StateCodeEnum.LackSubmitParam;
                    reslut.Msg = "提交参数不能为空";
                    #endregion
                }
                else
                {
                    #region 主要业务

                    UserInfo userInfo = _userService.GetUserInfoById(dayProjectDetailRequestrBodyParamDto.UserId);

                    if (userInfo != null)
                    {


                        #region 用户存在
                        string encryptAuth = EncryptionUtils.GetUserLoginAuth_SHA1(userInfo.LogonName, userInfo.LogonPwd);
                        if (encryptAuth == dayProjectDetailRequestrBodyParamDto.Auth)
                        {
                            #region 密码正确 业务主体
                            DayProjectInfo dayProjectInfo = _projectManageService.GetDayProjectInfoById(dayProjectDetailRequestrBodyParamDto.DayProjectId);
                            if (dayProjectInfo != null)
                            {
                                if (dayProjectInfo.UserId == dayProjectDetailRequestrBodyParamDto.UserId)
                                {
                                    dayProjectInfo.CompleteTime = DateTime.Now;
                                    dayProjectInfo.StatusType = 15;
                                    dayProjectInfo.UpdateTime = DateTime.Now;
                                    if (_projectManageService.UpdateDayProjectInfo(dayProjectInfo))
                                    {
                                        reslut.Code = StateCodeEnum.Ok;
                                        reslut.Msg = "操作成功!";
                                        reslut.Data = new Hashtable();
                                    }
                                    else
                                    {
                                        reslut.Code = StateCodeEnum.Fail;
                                        reslut.Msg = "操作失败!";
                                        reslut.Data = new Hashtable();
                                    }
                                }
                                else
                                {
                                    reslut.Code = StateCodeEnum.Fail;
                                    reslut.Msg = "非此人任务!";
                                    reslut.Data = new Hashtable();
                                }
                            }
                            else
                            {
                                reslut.Code = StateCodeEnum.Fail;
                                reslut.Msg = "操作失败!";
                                reslut.Data = new Hashtable();
                            }
                            #endregion
                        }
                        else
                        {
                            #region 密码不正确
                            reslut.Code = StateCodeEnum.Fail;
                            reslut.Msg = "密码不正确!";
                            #endregion

                        }
                        #endregion
                    }
                    else
                    {
                        #region 用户不存在
                        reslut.Code = StateCodeEnum.Fail;
                        reslut.Msg = "账号不存在";
                        #endregion
                    }

                    #endregion
                }
            }
            catch (Exception e)
            {
                reslut.Code = StateCodeEnum.InternalServerError;
                reslut.Msg = "服务器错误";

            }
            return Ok(reslut);
        }


        /// <summary>
        /// 0  任务未下发
        /// </summary>
        /// <param name="statusType"></param>
        /// <returns></returns>
        private string GetStatusTypeStr(int statusType)
        {
            string back = _projectManageService.GetStatusTypeStr(statusType);

            return back;
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="list"></param>
        /// <param name="dayProjectTypeId"></param>
        /// <returns></returns>
        private string GetDayProjectTypeStr(IList<DayProjectTypeInfo> list,int dayProjectTypeId)
        {
            string back = "";
            foreach(DayProjectTypeInfo item in list)
            {
                if(item.DayProjectTypeId== dayProjectTypeId)
                {
                    back = item.DayProjectTypeName;
                    break;
                }
            }
            return back;
        }

        /// <summary>
        /// 退出登录
        /// </summary>
        /// <param name="userIdTokenRequestBodyParamDto"></param>
        /// <returns></returns>
        //[Authorize]
        [HttpPost, Route("UserLayout")]
        public IActionResult UserLayout([FromBody] UserIdTokenRequestBodyParamDto userIdTokenRequestBodyParamDto)
        {
            ApiRequestCustomHeadInfo apiRequestCustomHeadInfo = RequestHeadHelper.GetApiRequestCustomHeadInfo(_httpContext.HttpContext);
            SSMSApiResult<Hashtable> reslut = new SSMSApiResult<Hashtable>();
            reslut.Code = StateCodeEnum.Ok;
            reslut.Data = new Hashtable();
            reslut.Msg = "操作成功";
            return Ok(reslut);
        }
        

    }
}
